const vscode = require('vscode');
const fs = require('fs').promises;
const path = require('path');

class CodeGenerator {
    constructor(projectAnalyzer) {
        this.analyzer = projectAnalyzer;
    }

    // 智能代码生成
    async generateSmartCode(content, targetPath) {
        try {
            const dir = path.dirname(targetPath);
            await fs.mkdir(dir, { recursive: true });

            // 直接写入新内容，忽略现有内容
            await this.writeFile(targetPath, content);
            return true;
        } catch (error) {
            console.error('Error generating smart code:', error);
            return false;
        }
    }

    // 写入文件
    async writeFile(filePath, content) {
        const dir = path.dirname(filePath);
        await fs.mkdir(dir, { recursive: true });
        await fs.writeFile(filePath, content, 'utf8');
    }
}

module.exports = CodeGenerator;